<%@page import="java.text.SimpleDateFormat"%>
<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt"%>
<%
	String path = request.getContextPath();
	String basePath = request.getScheme() + "://" + request.getServerName() + ":" + request.getServerPort()
			+ path + "/";
%>
<!doctype html>
<html>
	<head>
		<title>发布公告/客服信息 </title>
		<base href="<%=basePath%>" />
		<meta charset="utf-8">
		<meta http-equiv="X-UA-Compatible" content="IE=edge">
		<meta name="viewport" content="width=device-width, initial-scale=1">
		<meta name="renderer" content="webkit">
		<meta http-equiv="Cache-Control" content="no-siteapp" />
		<link rel="icon" type="image/png" href="i/buyu.ico">
		<link rel="apple-touch-icon-precomposed" href="i/app-icon72x72@2x.png">
		<link rel="stylesheet" href="layui/css/layui.css">
		<style type="text/css">
		.layui-input-inline > .layui-input  {
		    color : red;
		}
		.layui-form-item > .layui-form-label {
		    width:150px;
		}
		</style>
	</head>

	<body>
           <form class="layui-form" >
              <div class="layui-form-item">
                <label class="layui-form-label">标题</label>
                <div class="layui-input-inline">
                  <input type="text" name="title" autocomplete="off" id="title" class="layui-input">
                </div>
              </div>
              <div class="layui-form-item">
                <label class="layui-form-label">公告|客服</label>
                <div class="layui-input-inline">
                  <input  type="hidden" name="noticeType" id="noticeType" value="0">
		          <input type="checkbox" name="noticeSwitch" id="noticeSwitch" lay-skin="switch" lay-filter="noticeSwitch" lay-text="客服|公告">
                </div>
                <i class="layui-icon layui-icon-tips" style="font-size: 30px; color: #d71345; visibility : hidden;"></i> 
              </div>
           
			<div class="layui-form-item layui-form-text">
				<textarea name="contents" class="layui-textarea" id="contents" placeholder="公告内容最大支持120个字符，不支持繁体中文,$ &等特殊字符，会自动过滤空格和换行符"></textarea>
			</div>
			<div class="layui-input-block">
				<button type="submit" class="layui-btn" lay-submit lay-filter="go">发送</button>
				<button type="reset" class="layui-btn layui-btn-primary">重置</button>
			</div>
	    </form>
		

		<script src="js/jquery.min.js"></script>
		<script src="layui/layui.js"></script>
        <script>
        layui.use(['layer','form'], function () {
            var layer = layui.layer, 
                form = layui.form;
            
            //添加鼠标监听事件
            $(".layui-icon.layui-icon-tips")[0].addEventListener("mouseover",function(event) {
            	layer.tips('客服模式无标题，填写正文内容即可', '.layui-icon.layui-icon-tips', {
           		  tips: [1, '#3595CC'],
           		  time: 4000
           		});
            },false);
            
           	//监听复选器
           	form.on('switch(noticeSwitch)',function(data){
               	if (data.elem.checked === false) {
               		//这是公告操作
               		$("input[type=hidden][name=noticeType]").val('0');
               		$("#title").attr("disabled",false);
               		$(".layui-icon.layui-icon-tips")[0].style.visibility = ($(".layui-icon.layui-icon-tips")[0].style.visibility === "hidden")?"visible":"hidden";
               	}else {
               		//这是客服操作
               		$("input[type=hidden][name=noticeType]").val('1');
               		$("#title").val("");
               		$("#title").attr("disabled",true);
               		$(".layui-icon.layui-icon-tips")[0].style.visibility = ($(".layui-icon.layui-icon-tips")[0].style.visibility === "hidden")?"visible":"hidden";
               	}
               })
            form.on('submit(go)', function () {
            	if ($("input[type=hidden][name=noticeType]").val() === '0'){
	            	if($("#title").val() == "" || $("#title").val() == null){
	            		layer.msg("请填写标题");
	            		return false;
	            	}
            	}
            	if($("#contents").val() == "" || $("#contents").val() == null){
            		layer.msg("请填写标题内容");
            		return false;
            	}
            	
            	$.ajax({
            		type:'post',
            		url:"notice/add",
            		data:{
            			title:$("#title").val(),
            			noticeType :  $("input[type=hidden][name=noticeType]").val(),
            			contents:$("#contents").val()
            		},
            		success:function(data){
            			console.log(data);
	            	    if(data == "" || data == null){
	            			layer.msg("发布公告成功",{icon:1});
	            			setTimeout(function(){
	            				window.location.reload();
	            			},1000);
            			}else{
            				layer.msg(data,{icon:2});
            			}
            		},error:function(){
            			layer.msg("发布公告失败");
            		}
            	});
              return false;
            });
            });
        </script>
	</body>

</html>
